/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import dao.ClasseDAO;
import dao.FamiliaDAO;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import model.Classe;
import model.Familia;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;

/**
 * CADASTRO PADRÃO
 *
 * @author JONATAS
 *
 *
 */
public class FamiliaFrame extends javax.swing.JFrame {

    /**
     * Creates new form FamiliaFrame
     */
    public FamiliaFrame() {
        System.out.println("START");
        initComponents();
        System.out.println("INIT COMPOS. OK - SET STATUS  INICIAL");
        setStatusInicial();
        System.out.println("SET ST. OK = BUSCAR CLASSES");        
        buscarClassesCB();
        System.out.println("BUSCAR CLASSES OK");
        buscarTodos();
        System.out.println("BUSCAR TODOS OK");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        btnDeletar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tbCodigo = new javax.swing.JTextField();
        tbDescricao = new javax.swing.JTextField();
        cmbClasse = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem9 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        Relatório = new javax.swing.JMenu();
        jMenuItem13 = new javax.swing.JMenuItem();
        jMenuItem14 = new javax.swing.JMenuItem();
        jMenuItem15 = new javax.swing.JMenuItem();
        jMenuItem16 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem7 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Famílias");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                buscar(evt);
            }
        });

        btnDeletar.setText("Deletar");
        btnDeletar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeletarActionPerformed(evt);
            }
        });

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Família", "Descrição", "Classe"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setNextFocusableComponent(btnSalvar);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTable1MouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Código:");

        jLabel2.setText("Descrição: ");

        tbCodigo.setEditable(false);
        tbCodigo.setEnabled(false);
        tbCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbCodigoActionPerformed(evt);
            }
        });

        tbDescricao.setNextFocusableComponent(cmbClasse);
        tbDescricao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbDescricaoActionPerformed(evt);
            }
        });
        tbDescricao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbDescricaoKeyPressed(evt);
            }
        });

        cmbClasse.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione uma Marca" }));
        cmbClasse.setFocusCycleRoot(true);
        cmbClasse.setNextFocusableComponent(btnSalvar);
        cmbClasse.setOpaque(false);
        cmbClasse.setRequestFocusEnabled(false);
        cmbClasse.setVerifyInputWhenFocusTarget(false);
        cmbClasse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbClasseActionPerformed(evt);
            }
        });
        cmbClasse.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cmbClasseKeyPressed(evt);
            }
        });

        jLabel5.setText("Classe:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tbCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(tbDescricao)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(cmbClasse, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tbDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addGap(5, 5, 5)
                .addComponent(cmbClasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 13, Short.MAX_VALUE))
        );

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnSalvar.setText("Salvar");
        btnSalvar.setName("");
        btnSalvar.setNextFocusableComponent(tbDescricao);
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        jLabel3.setText("Famílias cadastradas:");

        jMenu1.setText("Cadastros");

        jMenuItem1.setText("Clientes");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem12.setText("Usuários");
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem12);
        jMenu1.add(jSeparator3);

        jMenuItem2.setText("Casses");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Famílias");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem8.setText("Produtos");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);
        jMenu1.add(jSeparator1);

        jMenuItem9.setText("Localização");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem9);
        jMenu1.add(jSeparator2);

        jMenuItem4.setText("Sair");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Projetos");

        jMenuItem5.setText("Gerenciar Projetos");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuItem6.setText("Consultar Projetos");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem6);

        jMenuItem10.setText("Imprimir Documento");
        jMenu2.add(jMenuItem10);

        jMenuBar1.add(jMenu2);

        Relatório.setText("Relatórios");

        jMenuItem13.setText("Relatório de Classes/Famílias");
        Relatório.add(jMenuItem13);

        jMenuItem14.setText("Relatório de Materiais");
        Relatório.add(jMenuItem14);

        jMenuItem15.setText("Relatório de Projetos");
        Relatório.add(jMenuItem15);

        jMenuItem16.setText("Relatório de Clientes");
        Relatório.add(jMenuItem16);

        jMenuBar1.add(Relatório);

        jMenu4.setText("Sobre");
        jMenuBar1.add(jMenu4);

        jMenu3.setText("Sair");

        jMenuItem7.setText("Sair");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem7);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnSalvar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDeletar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addGap(4, 4, 4)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDeletar)
                    .addComponent(btnCancelar)
                    .addComponent(btnSalvar))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-703)/2, (screenSize.height-712)/2, 703, 712);
    }// </editor-fold>//GEN-END:initComponents

    private void setStatusInicial() {

        status = 'I';
        tbCodigo.setText("Novo Registro");
        btnDeletar.setEnabled(false);
        tbDescricao.requestFocus();
    }

    private void setStatusAlterar() {

        status = 'A';
        btnDeletar.setEnabled(true);
    }

    private void limparCampos() {
        tbCodigo.setText("");
        tbDescricao.setText("");
    }

    private boolean verificaCamposNulos() {
        if (tbDescricao.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Campo descrição em branco!");
            tbDescricao.requestFocus();
            return false;
        }
        /*
         * if (cmbClasse.getSelectedIndex() == 0) {
         * JOptionPane.showMessageDialog(null, "Selecione uma classe!");
         * cmbClasse.requestFocus(); return false;
        }
         */
        return true;

    }
    private void tbCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tbCodigoActionPerformed

    private void tbDescricaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbDescricaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tbDescricaoActionPerformed

    private void buscar(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_buscar
        
    }//GEN-LAST:event_buscar

    private void buscarTodos() {
        // Carrega todos os dados da tabela Familia         
       
            List<Familia> lista = new FamiliaDAO().findAll();
            DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();            
            modelo.setNumRows(0);            

            for (Familia m : lista) {                
                modelo.addRow(new String[]{"" + m.getFam_id(), m.getFam_descricao(), m.getFam_classe().getCla_descricao()});                
            }            
        

    }

    private void selecionar() {

        // obtem o valor da linha selecionada
        int selecionada = jTable1.getSelectedRow();

        // obtem o valor da coluna
        String codigo = (String) jTable1.getValueAt(selecionada, 0);

        System.out.println("Selecionou Familia id -> " + codigo);

        m = dao.findById(codigo);

        tbCodigo.setText("" + m.getFam_id());
        tbDescricao.setText(m.getFam_descricao());
        cmbClasse.getModel().setSelectedItem(m.getFam_classe());
        setStatusAlterar();
        tbDescricao.requestFocus();
    }

    private void buscarClassesCB() {
        //List<Marca> lista = new MarcaDAO().findAll();


        DefaultComboBoxModel cmodel =
                new DefaultComboBoxModel(
                new Vector(new ClasseDAO().findAll()));

        cmbClasse.setModel(cmodel);

    }
    private void btnDeletarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeletarActionPerformed

        //  Classe m = dao.findById( Integer.parseInt(tbCodigo.getText()) ); 
        int opt;

        switch (status) {
            case 'D': // Ação de deletar mais de uma linha ao mesmo tempo

                opt = JOptionPane.showConfirmDialog(null, "Deseja excluir as Familias selecionadas? ");
                System.out.println("Option = -> " + opt);
                if (opt == 0) {
                    int[] selecionadas = jTable1.getSelectedRows();
                    String codigo;

                    for (int i = 0; i < jTable1.getSelectedRowCount(); i++) { // Apaga linha por linha selecionada
                        System.out.println(i + "a. de " + jTable1.getSelectedRowCount() + "Linha select -> " + selecionadas[i]);

                        codigo = (String) jTable1.getValueAt(selecionadas[i], 0);
                        System.out.println("Selecionou Familia id -> " + codigo);
                        m = dao.findById((codigo));
                        dao.delete(m);
                    }
                    buscar(null);
                    limparCampos();
                    setStatusInicial();
                } else {
                    setStatusInicial();
                }
                break;
            case 'A': // Deletar uma linha 
                opt = JOptionPane.showConfirmDialog(null, "Deseja excluir a Familia selecionada? ");
                System.out.println("Option = -> " + opt);
                if (opt == 0) {
                    dao.delete(m);
                    buscar(null);
                    limparCampos();
                    setStatusInicial();
                } else {
                    setStatusInicial();
                }
                break;
        }
    }//GEN-LAST:event_btnDeletarActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        selecionar();
        tbDescricao.requestFocus();
    }//GEN-LAST:event_jTable1MouseClicked

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        limparCampos();
        buscarTodos();
        setStatusInicial();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void tbDescricaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbDescricaoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) { //  Se pressionar enter éo mesmo que clicar no botao salvar
            btnSalvarActionPerformed(null);
        }
        if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) { // Se pressionar ESQ é o mesmo que Cancelar
            btnCancelarActionPerformed(null);
        }


        /*
         * Exemplo para usar um DIALOG
         *
         * if (evt.getKeyCode() == KeyEvent.VK_F2) { // Se pressionar F2
         * seleciona ClasseDialog cd = new ClasseDialog(null, true);
         * cd.setVisible(true); tbCodigo.setText(cd.getClasse().getCla_id()+"");
         * tbDescricao.setText(cd.getClasse().getCla_descricao());
         * setStatusAlterar();
        }
         */
    }//GEN-LAST:event_tbDescricaoKeyPressed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed

        switch (status) {
            case 'I': // Status de  Inserir

                m = new Familia();
                m.setFam_descricao(tbDescricao.getText());
                m.setFam_classe((Classe) cmbClasse.getSelectedItem());

                // O retorno do verifica  campos nulos é TRUE ou FALSE - dápra usar direto no IF
                if (verificaCamposNulos()) {
                    m.setFam_id(dao.getCode());
                    dao.insert(m);
                    buscarTodos();
                    limparCampos();
                    setStatusInicial();
                }
                break;
            case 'A': // Status de Alterar

                m.setFam_descricao(tbDescricao.getText());
                m.setFam_classe((Classe) cmbClasse.getSelectedItem());
                if (verificaCamposNulos()) {
                    dao.update(m);
                    buscarTodos();
                    limparCampos();
                    setStatusInicial();
                }
                break;
        }


    }//GEN-LAST:event_btnSalvarActionPerformed

    private void jTable1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseReleased

        /*
         * Quando o usuário seleciona várias linhas o sistema permite deletar
         * todas de uma vez
         */
        limparCampos();
        status = 'D';
        btnDeletar.setEnabled(true);

    }//GEN-LAST:event_jTable1MouseReleased

    private void cmbClasseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbClasseActionPerformed
    }//GEN-LAST:event_cmbClasseActionPerformed

    private void cmbClasseKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbClasseKeyPressed
        /*
         * if (evt.getKeyCode() == KeyEvent.VK_ENTER) { // Se pressionar enter
         * éo mesmo que clicar no botao salvar btnSalvarActionPerformed(null);
        }
         */
        if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) { // Se pressionar ESQ é o mesmo que Cancelar
            btnCancelarActionPerformed(null);
        }

    }//GEN-LAST:event_cmbClasseKeyPressed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        ClienteFrame cf = new ClienteFrame();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed
        UsuarioFrame cf = new UsuarioFrame();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem12ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        ClasseFrame cf = new ClasseFrame();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        FamiliaFrame cf = new FamiliaFrame();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        MaterialFrameTab1 cf = new MaterialFrameTab1();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        LocalizaFrame cf = new LocalizaFrame();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        System.exit(1);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        ProjetoFrame cf = new ProjetoFrame();
        cf.setVisible(true);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed

   }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        System.exit(1);
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FamiliaFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FamiliaFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FamiliaFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FamiliaFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FamiliaFrame().setVisible(true);

            }
        });
    }
    private char status = 'I'; /*
     * I -> Inserir A -> Alterar D-> DELETAR INTERVALO
     */

    private FamiliaDAO dao = new FamiliaDAO();
    private Familia m = new Familia();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu Relatório;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnDeletar;
    private javax.swing.JButton btnSalvar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cmbClasse;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem13;
    private javax.swing.JMenuItem jMenuItem14;
    private javax.swing.JMenuItem jMenuItem15;
    private javax.swing.JMenuItem jMenuItem16;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField tbCodigo;
    private javax.swing.JTextField tbDescricao;
    // End of variables declaration//GEN-END:variables
}
